icontheme: Don't assume a symbolic icon size of 16x16
authorCarlos Garnacho <carlosg@gnome.org>
Wed, 6 Jun 2012 16:16:05 +0000 (18:16 +0200)
committerCarlos Garnacho <carlos@lanedo.com>
Fri, 13 Jul 2012 12:44:05 +0000 (14:44 +0200)
If the symbolic icon has other size than 16x16, the embedder
SVG that overrides colors would still force that size, resulting
in clipping instead of resizing. So fetch the original pixbuf
size the first time a symbolic icon is requested for a GtkIconInfo,
and use that size for the embedder SVG so it can be scaled properly
afterwards.

https://bugzilla.gnome.org/show_bug.cgi?id=677567

gtk/gtkicontheme.c

index fb598370162a7853150325606b5a8da5759c175c..58b643fcdbc2b8bee5c6dd0d94d87dce13bc5976 100644 (file)
@@ -232,6 +232,8 @@ struct _GtkIconInfo
   GdkPixbuf *pixbuf;
   GError *load_error;
   gdouble scale;
+
+  GtkRequisition *symbolic_pixbuf_size;
 };
 
 typedef struct
@@ -2737,6 +2739,8 @@ gtk_icon_info_free (GtkIconInfo *icon_info)
     g_object_unref (icon_info->pixbuf);
   if (icon_info->cache_pixbuf)
     g_object_unref (icon_info->cache_pixbuf);
+  if (icon_info->symbolic_pixbuf_size)
+    gtk_requisition_free (icon_info->symbolic_pixbuf_size);
 
   g_slice_free (GtkIconInfo, icon_info);
 }
@@ -3169,6 +3173,7 @@ _gtk_icon_info_load_symbolic_internal (GtkIconInfo  *icon_info,
   GdkPixbuf *pixbuf;
   gchar *data;
   gchar *success, *warning, *err;
+  gchar *width, *height;
 
   /* css_fg can't possibly have failed, otherwise
    * that would mean we have a broken style */
@@ -3192,13 +3197,29 @@ _gtk_icon_info_load_symbolic_internal (GtkIconInfo  *icon_info,
       err = gdk_color_to_css (&error_default_color);
     }
 
+  if (!icon_info->symbolic_pixbuf_size)
+    {
+      /* Fetch size from the original icon */
+      pixbuf = gdk_pixbuf_new_from_file (icon_info->filename, error);
+
+      if (!pixbuf)
+        return NULL;
+
+      icon_info->symbolic_pixbuf_size = gtk_requisition_new ();
+      icon_info->symbolic_pixbuf_size->width = gdk_pixbuf_get_width (pixbuf);
+      icon_info->symbolic_pixbuf_size->height = gdk_pixbuf_get_height (pixbuf);
+      g_object_unref (pixbuf);
+    }
+
+  width = g_strdup_printf ("%d", icon_info->symbolic_pixbuf_size->width);
+  height = g_strdup_printf ("%d", icon_info->symbolic_pixbuf_size->height);
 
   data = g_strconcat ("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
                       "<svg version=\"1.1\"\n"
                       "     xmlns=\"http://www.w3.org/2000/svg\"\n"
                       "     xmlns:xi=\"http://www.w3.org/2001/XInclude\"\n"
-                      "     width=\"16\"\n"
-                      "     height=\"16\">\n"
+                      "     width=\"", width, "\"\n"
+                      "     height=\"", height, "\">\n"
                       "  <style type=\"text/css\">\n"
                       "    rect,path {\n"
                       "      fill: ", css_fg," !important;\n"
@@ -3219,6 +3240,8 @@ _gtk_icon_info_load_symbolic_internal (GtkIconInfo  *icon_info,
   g_free (warning);
   g_free (err);
   g_free (success);
+  g_free (width);
+  g_free (height);
 
   stream = g_memory_input_stream_new_from_data (data, -1, g_free);
   pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream,